/**
 * Copyright (C), 2001-2031, www.bosssof.com.cn
 * FileName: GlobalExceptionHandler.java
 * Author: shixianwei
 * Date: 2024/8/17 21:06
 * Description:
 * <p>
 * History:
 * Date          Author   Version  Desc
 * 2024-01-01    bosssoft  1.0.0   initialize this file
 */
package com.bosssoft.setp.exception;

import com.bosssoft.setp.pojo.vo.Result;
import com.bosssoft.setp.utils.CommonResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ConstraintViolationException;

/**
 * @className: GlobalExceptionHandler
 * @description:
 * 全局异常处理
 * @author: shixianwei
 * @date: 2024/8/17 21:06
 * @since 1.0
 **/

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {



    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException ex){
        log.error("触发业务异常",ex);
        return Result.error(ex.getMessage());
    }


    /**
     * 处理其他所有的异常
     * @param ex 异常  demo重点 算术异常，SQL异常都归集这里处理
     * @return  公共报文模拟
     */
    @ExceptionHandler(Exception.class)
    public Result handleConstraintException(Exception ex){
        log.error("其他类型异常",ex);
        return Result.error("其他类型异常");
    }
}

